<?php

class Quad_Orm_Metadata_Mysql {
	
	public static function getTableNames() {
		$sql = "SHOW TABLES";
		$data = DB::getInstance()->selectColumnar($sql);
		return $data->cols[0];
	}
	
	public static function getTableMetadata($table) {
		$this->table = $table;
		$sql = "DESCRIBE `$this->table`";
		$fieldList = DB::getInstance()->select($sql);
		$cols = array();
		$pks = array();
		foreach ($fieldList as $field) {
			$cols[] = $field['Field'];
			if ($field['Key'] == 'PRI') {
				$pks[] = $field['Field'];
			}
		}
		$metadata = array(
			'columns'=>$cols,
			'primaryKeys'=>$pks
		);
		return $metadata;
	}
	
}
